package LearnAlgorithm.h_标准数学公式;
/*
double[] arr = new double[] {1, 1/2, 1/3, 1/4, 1/5, ..., 1/n};

Sn 近似等于 ln(n) + O(1);
 */
public class e调和级数 {
	public static void main(String[] args) {
		
		double[] arr0 = new double[50000];
		arr0[0] = 1D;
		for (int i = 1; i < arr0.length; i++) {
			arr0[i] = 1D / (i + 1);
		}
		double[] arr = new double[] {1D, (1D/2), (1D/3), (1D/4), (1D/5)};
//		for (int i = 0; i < arr.length; i++) {
//			System.out.println(arr[i]);
//		}
		
		System.out.println(HarmonicProgression(arr0));
		System.out.println(HarmonicProgression(arr0) + 0.5772256648682212);
		System.out.println(sum(arr0));
		System.out.println("差值是：" + (sum(arr0) - HarmonicProgression(arr0)));//0.5772256648682212
	}
	
	/**
	 * 近似结果
	 * 只能求一个近似结果值
	 * @param arr
	 * @return
	 */
	public static double HarmonicProgression(double[] arr) {
		return Math.log(arr.length);
	}
	
	/**
	 * 绝对结果
	 * @param arr
	 * @return
	 */
	public static double sum(double[] arr) {
		double sum = 0.0;
		for (int i = 0; i < arr.length; i++) {
			sum = (sum + arr[i]);
		}
		return sum;
	}
}
